<?php
class Tourismreviews extends CS_Controller
{
    public function _init()
    {
        $this->load->library('pagination');
        $this->load->model('tourism_order_reviews_model', 'tourism_order_reviews');
        $this->load->model('tourism_reviews_reply_model', 'tourism_reviews_reply');
    }
    
    /**
     * 产品评价列表
     * @param number $pg
     */
    public function grid($pg = 1)
    {
        $getData = $this->input->get();
        $getData['seller_uid'] = $this->uid;
        $page_num = 15;
        $num = ($pg - 1) * $page_num;
        $config['first_url'] = base_url('tourismreviews/grid').$this->pageGetParam($this->input->get());
        $config['suffix'] = $this->pageGetParam($this->input->get());
        $config['base_url'] = base_url('tourismreviews/grid');
        $config['total_rows'] = $this->tourism_order_reviews->total($getData);
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        $data['pg_link'] = $this->pagination->create_links();
        $data['page_list'] = $this->tourism_order_reviews->page_list($page_num, $num, $getData);
        $data['all_rows'] = $config['total_rows'];
        $data['pg_now'] = $pg;
        $data['pg_num'] = $page_num;
        $this->load->view('tourismreviews/grid', $data);
    }
    
    /**
     * 根据评价Id查看评价详情
     * @param unknown $goods_attr_id
     */
    public function detail($review_id)
    {
        $result = $this->tourism_order_reviews->findByReviewId(array('review_id'=>$review_id));
        if ($result->num_rows() <= 0) {
            $this->error('tourismreviews/grid', '', '此产品尚未评价，或者产品信息有误');
        }
        $data['reviewDetail'] = $result;
        $this->load->view('tourismreviews/detail', $data);
    }
    
    public function reviewsReply()
    {
        if ($this->validateParam($this->input->post('reply_user_name'))) {
            $_POST['reply_user_name'] = $this->userName;
        }
        if ($this->validateParam($this->input->post('reply_user_name'))) {
            $this->error('tourismreviews/detail', $this->input->post('review_id'), '保存出错，请刷新页面重新');
        }
        $result = $this->tourism_reviews_reply->reviewsReply($this->input->post());
        
        if ($result) {
            $this->success('tourismreviews/detail', $this->input->post('review_id'), '回复评价成功');
        } else {
            $this->error('tourismreviews/detail', $this->input->post('review_id'), '回复评价失败');
        }
    }
}